package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/canvas"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/dialog"
	"fyne.io/fyne/v2/driver/desktop"
	"fyne.io/fyne/v2/widget"
)

type MyClickable struct {
	widget.BaseWidget
}

func NewMyClickable() *MyClickable {
	m := &MyClickable{}
	m.ExtendBaseWidget(m)
	return m
}

func (m *MyClickable) CreateRenderer() fyne.WidgetRenderer {
	rectangle := canvas.NewRectangle(nil)
	return widget.NewSimpleRenderer(rectangle)
}

func (m *MyClickable) TappedSecondary() {
	dialog.ShowInformation("信息", "你右击了输入框！", nil)
}

func main() {
	myApp := app.New()
	myWindow := myApp.NewWindow("右击示例")

	// 创建输入框
	entry := NewMyEntry()
	entry.(*MyEntry).SetText("右击我")
	// 创建自定义可点击组件
	clickable := NewMyClickable()

	entry2 := widget.NewEntry()
	entry2.SetPlaceHolder("请输入文本")
	entryContainer := container.NewMax(entry2)
	entryContainer.Resize(fyne.NewSize(300, 50)) // 设置容器大小

	// 使用容器将输入框和自定义组件组合
	content := container.NewVBox(entry, entryContainer, widget.NewEntry(), clickable)

	// 设置窗口内容
	myWindow.SetContent(content)
	myWindow.Resize(fyne.NewSize(300, 200))
	myWindow.ShowAndRun()
}

type MyEntry struct {
	*widget.Entry
}

func NewMyEntry() fyne.CanvasObject {
	o := &MyEntry{
		Entry: widget.NewEntry(),
	}

	o.ExtendBaseWidget(o.Entry)

	return o
}

// MouseDown called on mouse click, this triggers a mouse click which can move the cursor,
// update the existing selection (if shift is held), or start a selection dragging operation.
//
// Implements: desktop.Mouseable
func (e *MyEntry) MouseDown(m *desktop.MouseEvent) {
	//e.Entry.MouseDown(m)
}
func (e *MyEntry) MinSize() fyne.Size {
	return e.Entry.MinSize()
}
func (e *MyEntry) TappedSecondary(pe *fyne.PointEvent) {

}
